package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.TaxiGangHandler;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.map.MapView.PanelType;
import com.taxigang.shared.TaxiGangInfo;

public class NewMessage extends TaxiGangPanel {

	private static NewMessageUiBinder uiBinder = GWT
			.create(NewMessageUiBinder.class);

	interface NewMessageUiBinder extends UiBinder<Widget, NewMessage> {
	}

	public NewMessage() {
		initWidget(uiBinder.createAndBindUi(this));
		bind();
	}

	@UiField Button sendMessageButton;
	@UiField Button cancelButton;
	@UiField TextArea messageTextArea;
	@UiField
	Label headerLabel;



	private void bind(){
		sendMessageButton.setText(TaxiGangCreator.taxiGangConstants.sendMessage());
		cancelButton.setText(TaxiGangCreator.taxiGangConstants.cancel());
		headerLabel.setText(TaxiGangCreator.taxiGangConstants.newMessage());

		sendMessageButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				TaxiGangInfo taxiganginfo = Session.getInstance().getCurrentMyTaxiGang();
				
				TaxiGangHandler.getInstance().addMessage(taxiganginfo, messageTextArea.getText());
			}
		});

		cancelButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				taxiGangRoute.show(PanelType.MESSAGES);
			}
		});

	}

}
